local M = {
    "folke/which-key.nvim",
    dependencies = {
        { "nvim-tree/nvim-web-devicons", version = false },
    },
    event = "UIEnter",
    opts = {},
    keys = {
        {
            "<leader>?",
            function()
                require("which-key").show { global = false }
            end,
            desc = "Local Keymaps",
        },
    },
}

-- 定义一个函数，用于插入当前时间的注释
local function insert_current_time_comment()
    local current_time = os.date "%Y-%m-%d %H:%M:%S"
    vim.api.nvim_put({ current_time }, "l", false, true)
end

M.config = function()
    local wk = require "which-key"
    wk.add {
        { "<leader>b", group = "buffer" },

        { "<leader>c", group = "代码/颜色" },
        { "<leader>cb", group = "comment box" },
        { "<leader>cp", group = "颜色选择" },
        { "<leader>cs", "<esc>:'<,'>sort<cr>", desc = "排序", remap = true },

        { "<leader>d", group = "dap" },
        { "<leader>f", group = "file/telescope" },

        { "<leader>g", group = "git" },

        { "<leader>h", group = "帮助" },
        { "<leader>hd", group = "文档" },

        { "<leader>i", group = "插入" },
        {
            "<leader>it",
            function()
                insert_current_time_comment()
            end,
            desc = "插入时间",
        },

        { "<leader>j", group = "跳转" },

        { "<leader>l", group = "lsp" },
        { "<leader>lg", group = "golang" },
        { "<leader>lgf", group = "填充" },
        { "<leader>lgt", group = "tag" },
        { "<leader>lgz", group = "goctl" },
        { "<leader>ll", group = "变量打印" },

        { "<leader>lp", group = "lsp picker" },

        { "<leader>lm", group = "markdown" },
        { "<leader>lmt", group = "markdown table" },

        { "<leader>n", group = "notify" },

        { "<leader>p", group = "paste" },
        { "<leader>pp", group = "复制" },

        { "<leader>q", group = "退出" },
        { "<leader>qq", "<esc>:q!<cr>", desc = "强制退出" },

        { "<leader>r", group = "rename" },

        { "<leader>s", group = "搜索/展示/say" },
        { "<leader>sp", group = "snippy" },

        { "<leader>t", group = "test/todo" },
        { "<leader>tt", group = "长行虚拟字符" },
        { "<leader>td", group = "todo" },

        { "<leader>w", group = "窗口" },
        { "<leader>wq", "<esc>:q!<cr>", desc = "强制退出" },
        { "<leader>we", "<esc>:wq!<cr>", desc = "强制保存并退出" },
        { "<leader>ws", "<esc><CTRL-w>", desc = "分割" },
        { "<leader>ww", "<esc>:w!<cr>", desc = "强制保存" },

        { "<leader>x", group = "trouble" },
        { "<leader>xL", hidden = true },
        { "<leader>xQ", hidden = true },
        { "<leader>xl", "<cmd>Lazy<cr>", desc = "lazy" },

        { "<leader>z", group = "折叠" },
    }
    wk.setup {
        preset = "helix",
    }
end

return M
